const { Sequelize } = require('sequelize');
const configFn = require('./config/config.default.js');
const appConfig = configFn({ name: 'lingxi-system' });

// 创建数据库连接
const sequelize = new Sequelize(appConfig.sequelize.database, appConfig.sequelize.username, appConfig.sequelize.password, {
  host: appConfig.sequelize.host,
  port: appConfig.sequelize.port,
  dialect: appConfig.sequelize.dialect,
  timezone: appConfig.sequelize.timezone,
  define: appConfig.sequelize.define,
  logging: false, // 关闭SQL日志
});

async function checkDataItems() {
  try {
    // 测试数据库连接
    await sequelize.authenticate();
    console.log('数据库连接成功');
    
    // 查询特定批次的数据项
    const batchId = 'batch_1763968563435_4r6i70dcf';
    const items = await sequelize.query(
      'SELECT * FROM plugin_data_items WHERE batch_id = ?', 
      { 
        type: sequelize.QueryTypes.SELECT,
        replacements: [batchId]
      }
    );
    
    console.log('数据项信息:');
    console.log('数据项数量:', items.length);
    items.forEach((item, index) => {
      console.log(`数据项 ${index + 1}:`);
      console.log(`  ID: ${item.id}`);
      console.log(`  项目ID: ${item.item_id}`);
      console.log(`  URL: ${item.url}`);
      console.log(`  方法: ${item.method}`);
      console.log(`  类别: ${item.category}`);
      console.log(`  状态: ${item.status}`);
      console.log(`  创建时间: ${item.created_at}`);
      if (item.error_message) {
        console.log(`  错误信息: ${item.error_message}`);
      }
      console.log('---');
    });
    
  } catch (error) {
    console.error('查询数据时出错:', error);
  } finally {
    await sequelize.close();
  }
}

checkDataItems();